package main

import (
	"fmt"
	"log"
	"net"
)

func main() {
	addr, err := net.ResolveTCPAddr("tcp", ":8888")
	if err != nil {
		log.Println("resolve addr error:", err)
		return
	}
	conn, err := net.DialTCP("tcp", nil, addr)
	if err != nil {
		log.Println("dial error:", err)
		return
	}
	request(conn)
}

func request(conn net.Conn) {
	_, err := conn.Write([]byte("PING"))
	if err != nil {
		log.Println("write error:", err.Error())
		return
	}
	buf := make([]byte, 1024)
	n, err := conn.Read(buf)
	if err != nil {
		log.Println("read error:", err.Error())
		return
	}
	log.Printf("got %d bytes.\n", n)
	fmt.Println(string(buf[:n]))
}
